package org.example.controller;

import org.example.entity.Equipment;
import org.example.entity.Location;
import org.example.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author CoderXshuai
 * @date 2020/9/1/0001 15:10
 */
@Controller
@RequestMapping("/equipment")
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;

    @RequestMapping("/findAllByLid")
    @ResponseBody
    public List<Equipment> findAllByLid() {
        return equipmentService.findAllEquipment();
    }

    @RequestMapping("/updateEquipment")
    @ResponseBody
    public Equipment updateEquipment(@RequestBody Equipment equipment) {
        equipmentService.updateEquipment(equipment);
        return equipment;
    }

    @RequestMapping("/deleteEquipment")
    public String[] deleteEquipment(@RequestParam String[] eidList) {
        for (String eid : eidList) {
            equipmentService.deleteEquipment(Integer.parseInt(eid));
        }
        return eidList;
    }

    @RequestMapping("/insertEquipment")
    @ResponseBody
    public Equipment insertEquipment(@RequestBody Equipment equipment) {
        equipmentService.insertEquipment(equipment);
        return equipment;
    }
}
